package com.cs171.market.Repository;


import com.cs171.market.entity.Good;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


/**
 * (Good)商品实体类
 *
 * @author yangyifei
 * @since 2020-05-01 16:33:59
 */
@Repository
public interface GoodRepository extends JpaRepository<Good, Integer> {
    /**
     * 根据展示部位和展示类别输出数据库所有数据
     * @param part：热卖榜单还是精选生鲜
     * @param type：果蔬还是海鲜
     * @return 数据库对应的多条数据
     */
    // hql是面向对象的查询，而不是面向数据库表的查询，因此在hql语句中的对象名必须与实体类的类名一致，严格区分大小写，如本例Good
    //@Query("select g.gname as title,g.carousel,g.gprice as price,g.originprice as originPrice,g.deliveryprice as deliveryPrice,g.sold,g.gnum as stock, g.choices,g.deliverytime as deliveryTime, g.gimg as descImg from Good as g where g.gid=?1")
    @Query("select t.gid as id,t.gname as descp ,t.gprice as price,t.gimg as imgUrl from Good t where t.gdesc=?1 and t.gtype=?2 ")
    List<Map<String, Object>> getHeaderJsonAboutGoods(String part, String type);

    @Query("select t.gid as id,t.gname as descp ,t.gprice as price,t.gimg as imgUrl from Good t where t.gtype=?1 ")
    List<Map<String, Object>> getClassifyJsonAboutGoods(String type);

    @Query("select t.gid as id,t.gname as name ,t.gprice as price,t.gimg as imgUrl from Good t where t.gtype=?1 ")
    List<Map<String, Object>> getClassifynameJsonAboutGoods(String type);

    @Query("select t.gid as id,t.gname as descp ,t.gprice as price,t.gimg as imgUrl from Good t where t.gdesc=?1 ")
    List<Map<String, Object>> recommendJsonAboutGoods(String part);

    @Query("select t.gid as id,t.gname as name ,t.gprice as price,t.gimg as imgUrl from Good t where t.gdesc=?1 ")
    List<Map<String, Object>> recommendnameJsonAboutGoods(String part);

    @Query("select t.gid as id,t.gname as title ,t.gprice as price,t.originprice as originPrice,t.gimg as imgUrl,t.gtype as category,t.sold as sold,t.gdescp as descp from Good t")
    List<Map<String, Object>> searchJsonAboutGoods();

}
